    #include <cstring>
    #include <iostream>
    #include <opencv2/core/utility.hpp>
    #include <opencv2/highgui.hpp>
    #include <opencv2/tracking.hpp>
    #include <opencv2/videoio.hpp>
    using namespace std;
    using namespace cv;
    
int calFPS()
{
	using namespace std;
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#define dxnum 1.0
#else
#define dxnum 0.0001
#endif
	static int dtime;
	static int cnt = 0;
	static long time = 0;
	static int temp = -1;
	cnt++;
	dtime += dxnum*(clock()-time);
	time = clock();
	if (dtime>=1000)
	{
		dtime = 0;
		temp = cnt;
		cnt = 0;
	}
	cout<<"FPS:"<<temp<<endl;
	return temp;
	
}
    int main() {
    Rect roi;
    Mat frame;
    // 灰度图需要设置参数 不是灰度图可按照默认参数
    TrackerKCF::Params param;
    param.desc_pca = TrackerKCF::GRAY;
    param.compressed_size = 0x01;
    param.detect_thresh = 0.2;
    //参数设置结束
    //Ptr<TrackerKCF> tracker = TrackerKCF::create(param);
cv::Ptr<cv::Tracker> tracker = cv::TrackerCSRT::create();
    VideoCapture Sequence(0);
    Sequence >> frame;
    while (1) {
    char key = waitKey(1);
    Sequence >> frame;
    if (key == 'e') // 按e键退出跳帧
    {
    break;
    }
    imshow("image", frame);
    }


    cv::destroyWindow("image");

    roi = selectROI("tracker", frame);

    if (roi.width == 0 || roi.height == 0)
    return 0;

    tracker->init(frame, roi);

    int ncnt = 0;
    printf("Start the tracking process\n");
    for (;;) {
    // get frame from the video
    calFPS();
    Sequence >> frame;
    // stop the program if no more images
    if (frame.rows == 0 || frame.cols == 0) {
    cv::destroyWindow("tracker");
    break;
    }
    // update the tracking result
    tracker->update(frame, roi);
    // draw the tracked object
    rectangle(frame, roi, Scalar(255, 0, 0), 2, 1);
    // show image with the tracked object
    imshow("tracker", frame);
    // quit on ESC button
    if (char(waitKey(1)) == 'q') {
    cv::destroyWindow("tracker");
    break;
    }
    }
    return 0;
    }




